﻿//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 文件名: CrmLinkMan.cs
// 作 者：代码自动生成
// 日 期：2012-6-12 9:59:30
// 描 述：
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using Csla;
using lite;
using Csla.Validation;
using Csla.Data;
using System.Data.SqlClient;
using ZX.DAL;
using OpenExpressApp.ORM;

namespace ZX.CRM.Library
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    [Table(Name = "CrmLinkMan")]
    [ZX.DBModule.Table("CrmLinkMan", "ID")]
    public class CrmLinkMan : ZX.DBModule.BaseEntity
    {

        #region Business Methods 业务方法

        /// <summary>
        /// ID
        /// </summary>
        private static PropertyInfo<Guid> IDProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<Guid>("ID"));
        [DataObjectField(true, true)]
        [Column, PK]
        public Guid ID
        {
            get { return GetProperty(IDProperty); }
            set { SetProperty(IDProperty, value); }
        }

        /// <summary>
        /// 客户联系人编码
        /// </summary>
        private static PropertyInfo<string> CodeProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Code"));
        [Column]
        public string Code
        {
            get { return GetProperty(CodeProperty); }
            set { SetProperty(CodeProperty, value); }
        }
        /// <summary>
        /// 客户联系人名称
        /// </summary>
        private static PropertyInfo<string> CaptionProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Caption"));
        [Column]
        public string Caption
        {
            get { return GetProperty(CaptionProperty); }
            set { SetProperty(CaptionProperty, value); }
        }
        /// <summary>
        /// 客户ID
        /// </summary>
        private static PropertyInfo<Guid> CustomIdProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<Guid>("CustomId"));
        [Column]
        public Guid CustomId
        {
            get { return GetProperty(CustomIdProperty); }
            set { SetProperty(CustomIdProperty, value); }
        }
        /// <summary>
        /// 客户联系人类型Id
        /// </summary>
        private static PropertyInfo<Guid> TypeIDProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<Guid>("TypeID"));
        [Column]
        public Guid TypeID
        {
            get { return GetProperty(TypeIDProperty); }
            set { SetProperty(TypeIDProperty, value); }
        }
        /// <summary>
        /// 性别   F:女  M:男
        /// </summary>
        private static PropertyInfo<string> SexProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Sex"));
        [Column]
        public string Sex
        {
            get { return GetProperty(SexProperty); }
            set { SetProperty(SexProperty, value); }
        }
        /// <summary>
        /// 民族
        /// </summary>
        private static PropertyInfo<string> NationProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Nation"));
        [Column]
        public string Nation
        {
            get { return GetProperty(NationProperty); }
            set { SetProperty(NationProperty, value); }
        }
        /// <summary>
        /// 职位
        /// </summary>
        private static PropertyInfo<string> PositionProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Position"));
        [Column]
        public string Position
        {
            get { return GetProperty(PositionProperty); }
            set { SetProperty(PositionProperty, value); }
        }
        /// <summary>
        /// 所属部门
        /// </summary>
        private static PropertyInfo<string> DeptNameProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("DeptName"));
        [Column]
        public string DeptName
        {
            get { return GetProperty(DeptNameProperty); }
            set { SetProperty(DeptNameProperty, value); }
        }
        /// <summary>
        /// 生日类型   0：农历1：阳历
        /// </summary>
        private static PropertyInfo<string> BirthdayTypeProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("BirthdayType"));
        [Column]
        public string BirthdayType
        {
            get { return GetProperty(BirthdayTypeProperty); }
            set { SetProperty(BirthdayTypeProperty, value); }
        }
        /// <summary>
        /// 生日日期
        /// </summary>
        private static PropertyInfo<DateTime> BirthdayProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<DateTime>("Birthday"));
        [Column]
        public DateTime Birthday
        {
            get { return GetProperty(BirthdayProperty); }
            set { SetProperty(BirthdayProperty, value); }
        }
        /// <summary>
        /// 籍贯
        /// </summary>
        private static PropertyInfo<string> HomeplaceProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Homeplace"));
        [Column]
        public string Homeplace
        {
            get { return GetProperty(HomeplaceProperty); }
            set { SetProperty(HomeplaceProperty, value); }
        }
        /// <summary>
        /// 联系人个人网页
        /// </summary>
        private static PropertyInfo<string> NettingProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Netting"));
        [Column]
        public string Netting
        {
            get { return GetProperty(NettingProperty); }
            set { SetProperty(NettingProperty, value); }
        }
        /// <summary>
        /// 联系人传真
        /// </summary>
        private static PropertyInfo<string> FaxProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Fax"));
        [Column]
        public string Fax
        {
            get { return GetProperty(FaxProperty); }
            set { SetProperty(FaxProperty, value); }
        }
        /// <summary>
        /// 联系人移动电话
        /// </summary>
        private static PropertyInfo<string> MobileTelProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("MobileTel"));
        [Column]
        public string MobileTel
        {
            get { return GetProperty(MobileTelProperty); }
            set { SetProperty(MobileTelProperty, value); }
        }
        /// <summary>
        /// 联系人办公电话
        /// </summary>
        private static PropertyInfo<string> OfficeTelProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("OfficeTel"));
        [Column]
        public string OfficeTel
        {
            get { return GetProperty(OfficeTelProperty); }
            set { SetProperty(OfficeTelProperty, value); }
        }
        /// <summary>
        /// 联系人家庭电话
        /// </summary>
        private static PropertyInfo<string> HomeTelProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("HomeTel"));
        [Column]
        public string HomeTel
        {
            get { return GetProperty(HomeTelProperty); }
            set { SetProperty(HomeTelProperty, value); }
        }
        /// <summary>
        /// 联系人邮箱
        /// </summary>
        private static PropertyInfo<string> EmailProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Email"));
        [Column]
        public string Email
        {
            get { return GetProperty(EmailProperty); }
            set { SetProperty(EmailProperty, value); }
        }
        /// <summary>
        /// 联系人地址
        /// </summary>
        private static PropertyInfo<string> AddressProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Address"));
        [Column]
        public string Address
        {
            get { return GetProperty(AddressProperty); }
            set { SetProperty(AddressProperty, value); }
        }
        /// <summary>
        /// 毕业院校
        /// </summary>
        private static PropertyInfo<string> SchoolUntityProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("SchoolUntity"));
        [Column]
        public string SchoolUntity
        {
            get { return GetProperty(SchoolUntityProperty); }
            set { SetProperty(SchoolUntityProperty, value); }
        }
        /// <summary>
        /// 专业
        /// </summary>
        private static PropertyInfo<string> SchoolspecialityProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Schoolspeciality"));
        [Column]
        public string Schoolspeciality
        {
            get { return GetProperty(SchoolspecialityProperty); }
            set { SetProperty(SchoolspecialityProperty, value); }
        }
        /// <summary>
        /// 学历
        /// </summary>
        private static PropertyInfo<string> SchoolScientifcProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("SchoolScientifc"));
        [Column]
        public string SchoolScientifc
        {
            get { return GetProperty(SchoolScientifcProperty); }
            set { SetProperty(SchoolScientifcProperty, value); }
        }
        /// <summary>
        /// 病史
        /// </summary>
        private static PropertyInfo<string> MedicalProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Medical"));
        [Column]
        public string Medical
        {
            get { return GetProperty(MedicalProperty); }
            set { SetProperty(MedicalProperty, value); }
        }
        /// <summary>
        /// 宗教
        /// </summary>
        private static PropertyInfo<string> ReligionProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Religion"));
        [Column]
        public string Religion
        {
            get { return GetProperty(ReligionProperty); }
            set { SetProperty(ReligionProperty, value); }
        }
        /// <summary>
        /// 爱好
        /// </summary>
        private static PropertyInfo<string> LinkManFancyProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("LinkManFancy"));
        [Column]
        public string LinkManFancy
        {
            get { return GetProperty(LinkManFancyProperty); }
            set { SetProperty(LinkManFancyProperty, value); }
        }
        /// <summary>
        /// 配偶籍贯
        /// </summary>
        private static PropertyInfo<string> FereHomeplaceProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("FereHomeplace"));
        [Column]
        public string FereHomeplace
        {
            get { return GetProperty(FereHomeplaceProperty); }
            set { SetProperty(FereHomeplaceProperty, value); }
        }
        /// <summary>
        /// 配偶姓名
        /// </summary>
        private static PropertyInfo<string> FereNameProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("FereName"));
        [Column]
        public string FereName
        {
            get { return GetProperty(FereNameProperty); }
            set { SetProperty(FereNameProperty, value); }
        }
        /// <summary>
        /// 配偶生日日期
        /// </summary>
        private static PropertyInfo<string> FereBirthdayProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("FereBirthday"));
        [Column]
        public string FereBirthday
        {
            get { return GetProperty(FereBirthdayProperty); }
            set { SetProperty(FereBirthdayProperty, value); }
        }
        /// <summary>
        /// 配偶民族
        /// </summary>
        private static PropertyInfo<string> FereNationProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("FereNation"));
        [Column]
        public string FereNation
        {
            get { return GetProperty(FereNationProperty); }
            set { SetProperty(FereNationProperty, value); }
        }
        /// <summary>
        /// 配偶爱好
        /// </summary>
        private static PropertyInfo<string> FereFancyProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("FereFancy"));
        [Column]
        public string FereFancy
        {
            get { return GetProperty(FereFancyProperty); }
            set { SetProperty(FereFancyProperty, value); }
        }
        /// <summary>
        /// 配偶所在公司
        /// </summary>
        private static PropertyInfo<string> FereCompanyProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("FereCompany"));
        [Column]
        public string FereCompany
        {
            get { return GetProperty(FereCompanyProperty); }
            set { SetProperty(FereCompanyProperty, value); }
        }
        /// <summary>
        /// 子女姓名
        /// </summary>
        private static PropertyInfo<string> ChildNameProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("ChildName"));
        [Column]
        public string ChildName
        {
            get { return GetProperty(ChildNameProperty); }
            set { SetProperty(ChildNameProperty, value); }
        }
        /// <summary>
        /// 子女生日日期
        /// </summary>
        private static PropertyInfo<string> ChildBirthdayProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("ChildBirthday"));
        [Column]
        public string ChildBirthday
        {
            get { return GetProperty(ChildBirthdayProperty); }
            set { SetProperty(ChildBirthdayProperty, value); }
        }
        /// <summary>
        /// 子女爱好
        /// </summary>
        private static PropertyInfo<string> ChildFancyProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("ChildFancy"));
        [Column]
        public string ChildFancy
        {
            get { return GetProperty(ChildFancyProperty); }
            set { SetProperty(ChildFancyProperty, value); }
        }
        /// <summary>
        /// 子女所在公司
        /// </summary>
        private static PropertyInfo<string> ChildCompanyProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("ChildCompany"));
        [Column]
        public string ChildCompany
        {
            get { return GetProperty(ChildCompanyProperty); }
            set { SetProperty(ChildCompanyProperty, value); }
        }
        /// <summary>
        /// 喜欢的菜系
        /// </summary>
        private static PropertyInfo<string> DishProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Dish"));
        [Column]
        public string Dish
        {
            get { return GetProperty(DishProperty); }
            set { SetProperty(DishProperty, value); }
        }
        /// <summary>
        /// 吸烟习惯
        /// </summary>
        private static PropertyInfo<string> SmokeProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Smoke"));
        [Column]
        public string Smoke
        {
            get { return GetProperty(SmokeProperty); }
            set { SetProperty(SmokeProperty, value); }
        }
        /// <summary>
        /// 喝酒习惯
        /// </summary>
        private static PropertyInfo<string> DrinkProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Drink"));
        [Column]
        public string Drink
        {
            get { return GetProperty(DrinkProperty); }
            set { SetProperty(DrinkProperty, value); }
        }
        /// <summary>
        /// 度假方式
        /// </summary>
        private static PropertyInfo<string> HoliTypeProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("HoliType"));
        [Column]
        public string HoliType
        {
            get { return GetProperty(HoliTypeProperty); }
            set { SetProperty(HoliTypeProperty, value); }
        }
        /// <summary>
        /// 说明
        /// </summary>
        private static PropertyInfo<string> ExplainProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Explain"));
        [Column]
        public string Explain
        {
            get { return GetProperty(ExplainProperty); }
            set { SetProperty(ExplainProperty, value); }
        }
        /// <summary>
        /// 操作员编号
        /// </summary>
        private static PropertyInfo<Guid> AddUserProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<Guid>("AddUser"));
        [Column]
        public Guid AddUser
        {
            get { return GetProperty(AddUserProperty); }
            set { SetProperty(AddUserProperty, value); }
        }
        /// <summary>
        /// 新增时间
        /// </summary>
        private static PropertyInfo<DateTime> AddTimeProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<DateTime>("AddTime"));
        [Column]
        public DateTime AddTime
        {
            get { return GetProperty(AddTimeProperty); }
            set { SetProperty(AddTimeProperty, value); }
        }
        /// <summary>
        /// 备用1
        /// </summary>
        private static PropertyInfo<string> EXP1Property = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("EXP1"));
        [Column]
        public string EXP1
        {
            get { return GetProperty(EXP1Property); }
            set { SetProperty(EXP1Property, value); }
        }
        /// <summary>
        /// 备用2
        /// </summary>
        private static PropertyInfo<string> EXP2Property = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("EXP2"));
        [Column]
        public string EXP2
        {
            get { return GetProperty(EXP2Property); }
            set { SetProperty(EXP2Property, value); }
        }
        /// <summary>
        /// 备用3
        /// </summary>
        private static PropertyInfo<string> EXP3Property = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("EXP3"));
        [Column]
        public string EXP3
        {
            get { return GetProperty(EXP3Property); }
            set { SetProperty(EXP3Property, value); }
        }
        /// <summary>
        /// 备用4
        /// </summary>
        private static PropertyInfo<string> EXP4Property = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("EXP4"));
        [Column]
        public string EXP4
        {
            get { return GetProperty(EXP4Property); }
            set { SetProperty(EXP4Property, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<Guid> RelationProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<Guid>("Relation"));
        [Column]
        public Guid Relation
        {
            get { return GetProperty(RelationProperty); }
            set { SetProperty(RelationProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> WeiboProperty = RegisterProperty(typeof(CrmLinkMan), new PropertyInfo<string>("Weibo"));
        [Column]
        public string Weibo
        {
            get { return GetProperty(WeiboProperty); }
            set { SetProperty(WeiboProperty, value); }
        }

        #endregion

        #region Validation Rules 验证规则
        //将验证规则与业务对象的属性联系在一起
        protected override void AddBusinessRules()
        {
            //AddRule的第一个参数是委托变量，也就是说是方法的变量
            ValidationRules.AddRule(CommonRules.StringRequired, "Code");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Code", 15));
            ValidationRules.AddRule(CommonRules.StringRequired, "Caption");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Caption", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "Sex");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Sex", 1));
            ValidationRules.AddRule(CommonRules.StringRequired, "Nation");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Nation", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "Position");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Position", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "DeptName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("DeptName", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "BirthdayType");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("BirthdayType", 1));
            ValidationRules.AddRule(CommonRules.StringRequired, "Homeplace");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Homeplace", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "Netting");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Netting", 40));
            ValidationRules.AddRule(CommonRules.StringRequired, "Fax");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Fax", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "MobileTel");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("MobileTel", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "OfficeTel");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("OfficeTel", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "HomeTel");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("HomeTel", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "Email");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Email", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "Address");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Address", 100));
            ValidationRules.AddRule(CommonRules.StringRequired, "SchoolUntity");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("SchoolUntity", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "Schoolspeciality");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Schoolspeciality", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "SchoolScientifc");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("SchoolScientifc", 15));
            ValidationRules.AddRule(CommonRules.StringRequired, "Medical");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Medical", 100));
            ValidationRules.AddRule(CommonRules.StringRequired, "Religion");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Religion", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "LinkManFancy");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("LinkManFancy", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "FereHomeplace");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("FereHomeplace", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "FereName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("FereName", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "FereBirthday");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("FereBirthday", 40));
            ValidationRules.AddRule(CommonRules.StringRequired, "FereNation");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("FereNation", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "FereFancy");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("FereFancy", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "FereCompany");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("FereCompany", 40));
            ValidationRules.AddRule(CommonRules.StringRequired, "ChildName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("ChildName", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "ChildBirthday");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("ChildBirthday", 40));
            ValidationRules.AddRule(CommonRules.StringRequired, "ChildFancy");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("ChildFancy", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "ChildCompany");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("ChildCompany", 40));
            ValidationRules.AddRule(CommonRules.StringRequired, "Dish");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Dish", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "Smoke");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Smoke", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "Drink");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Drink", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "HoliType");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("HoliType", 20));
            ValidationRules.AddRule(CommonRules.StringRequired, "Explain");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Explain", 100));
            ValidationRules.AddRule(CommonRules.StringRequired, "EXP1");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("EXP1", 40));
            ValidationRules.AddRule(CommonRules.StringRequired, "EXP2");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("EXP2", 40));
            ValidationRules.AddRule(CommonRules.StringRequired, "EXP3");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("EXP3", 40));
            ValidationRules.AddRule(CommonRules.StringRequired, "EXP4");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("EXP4", 40));
            ValidationRules.AddRule(CommonRules.StringRequired, "Weibo");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Weibo", 50));
            //base.AddBusinessRules();
        }
        #endregion

        #region Factory Methods 工厂方法

        public CrmLinkMan() { }

        public static CrmLinkMan New()
        {
            return DataPortal.Create<CrmLinkMan>();
        }
        public static CrmLinkMan Get(Guid ID)
        {
            return DataPortal.Fetch<CrmLinkMan>(new SingleLazyCriteria<CrmLinkMan, Guid>(ID, false));
        }
        public static void Delete(Guid ID)
        {
            DataPortal.Delete(ID);
        }

        //public override CrmLinkMan Save()
        //{
        //return base.Save();
        //}
        #endregion

        #region Data Access 数据访问
        //由于DataPortal_create中没有对数据库的访问，所有标记了Runlocal特性，使得该方法只需在本地运行即可
        //如果代码中有访问数据库的方法，那么就不要用这个特性，使数据门户可以根据情况将此方法的运行选择在应用服务器还是本地
        [RunLocal()]
        protected override void DataPortal_Create()
        {
            //在此调用CheckRules对所有的属性进行验证规则的检查，这样检查只运行一次。
            ValidationRules.CheckRules();
        }


        //可以看到此方法没有标记任何特性
        //此方法要访问数据库所以不能标记本地，由于她没有任何数据库更新操作所以也无需事务性的保护
        //此方法调用结束后会隐含的调用MarkOld（）方法
        private void DataPortal_Fetch(Guid ID)
        {
            //通过连接字符串建立SQL连接对象，Using符号代表，范围释放的意思，SqlConnection对象会在此范围后被释放掉
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(ConnectionStringNames))
            {
                IDb db = DbFactory.Instance.GetDb(ctx.Connection);
                IQuery q = db.Query();
                q.Constrain("ID").Equal(ID);
                var data = db.Select<CrmLinkMan>(q)[0];
                LoadProperty(IDProperty, data.ID);
                LoadProperty(CodeProperty, data.Code);
                LoadProperty(CaptionProperty, data.Caption);
                LoadProperty(CustomIdProperty, data.CustomId);
                LoadProperty(TypeIDProperty, data.TypeID);
                LoadProperty(SexProperty, data.Sex);
                LoadProperty(NationProperty, data.Nation);
                LoadProperty(PositionProperty, data.Position);
                LoadProperty(DeptNameProperty, data.DeptName);
                LoadProperty(BirthdayTypeProperty, data.BirthdayType);
                LoadProperty(BirthdayProperty, data.Birthday);
                LoadProperty(HomeplaceProperty, data.Homeplace);
                LoadProperty(NettingProperty, data.Netting);
                LoadProperty(FaxProperty, data.Fax);
                LoadProperty(MobileTelProperty, data.MobileTel);
                LoadProperty(OfficeTelProperty, data.OfficeTel);
                LoadProperty(HomeTelProperty, data.HomeTel);
                LoadProperty(EmailProperty, data.Email);
                LoadProperty(AddressProperty, data.Address);
                LoadProperty(SchoolUntityProperty, data.SchoolUntity);
                LoadProperty(SchoolspecialityProperty, data.Schoolspeciality);
                LoadProperty(SchoolScientifcProperty, data.SchoolScientifc);
                LoadProperty(MedicalProperty, data.Medical);
                LoadProperty(ReligionProperty, data.Religion);
                LoadProperty(LinkManFancyProperty, data.LinkManFancy);
                LoadProperty(FereHomeplaceProperty, data.FereHomeplace);
                LoadProperty(FereNameProperty, data.FereName);
                LoadProperty(FereBirthdayProperty, data.FereBirthday);
                LoadProperty(FereNationProperty, data.FereNation);
                LoadProperty(FereFancyProperty, data.FereFancy);
                LoadProperty(FereCompanyProperty, data.FereCompany);
                LoadProperty(ChildNameProperty, data.ChildName);
                LoadProperty(ChildBirthdayProperty, data.ChildBirthday);
                LoadProperty(ChildFancyProperty, data.ChildFancy);
                LoadProperty(ChildCompanyProperty, data.ChildCompany);
                LoadProperty(DishProperty, data.Dish);
                LoadProperty(SmokeProperty, data.Smoke);
                LoadProperty(DrinkProperty, data.Drink);
                LoadProperty(HoliTypeProperty, data.HoliType);
                LoadProperty(ExplainProperty, data.Explain);
                LoadProperty(AddUserProperty, data.AddUser);
                LoadProperty(AddTimeProperty, data.AddTime);
                LoadProperty(EXP1Property, data.EXP1);
                LoadProperty(EXP2Property, data.EXP2);
                LoadProperty(EXP3Property, data.EXP3);
                LoadProperty(EXP4Property, data.EXP4);
                LoadProperty(RelationProperty, data.Relation);
                LoadProperty(WeiboProperty, data.Weibo);
            }
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            //依然是调用下面的方法删除的，只是他此时可以获得自己的Id
            DataPortal_Delete(IDProperty);
        }
        #endregion

    }
}

